package com.examsystem.service.impl;

import com.examsystem.dao.UserMapper;
import com.examsystem.service.UploadService;
import com.examsystem.pojo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;


/**
 * @author Administrator
 */
@Service("uploadServiceImpl")
public class UploadServiceImpl implements UploadService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 上传图片
     * @param imgPath  图片路径
     * @param id 用户id
     * @return  result结果集对象
     */
    @Override
    public Result uploadImg(String imgPath, int id) {
        int i = userMapper.updateUserImg(id, imgPath);
        String key = "userImg: "+id+imgPath;
        if (i >= 1 ){
            redisTemplate.opsForValue().set(key,imgPath);
            return Result.succ(imgPath);
        }else {
            return Result.fail("头像上传失败！");
        }
    }
}
